Code
library(tidyverse)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Lai Wei
August 22, 2022
Today’s challenge is to
Read in one (or more) of the following data sets, available in the posts/_data
folder, using the correct R package and command.
Add any comments or documentation as needed. More challenging data may require additional code chunks and documentation.
Using a combination of words and results of R commands, can you provide a high level description of the data? Describe as efficiently as possible where/how the data was (likely) gathered, indicate the cases and variables (both the interpretation and any details you deem useful to the reader to fully understand your chosen data).
# A tibble: 82,116 × 2
`Area Code` Area
<dbl> <chr>
1 2 Afghanistan
2 2 Afghanistan
3 2 Afghanistan
4 2 Afghanistan
5 2 Afghanistan
6 2 Afghanistan
7 2 Afghanistan
8 2 Afghanistan
9 2 Afghanistan
10 2 Afghanistan
# … with 82,106 more rows
# ℹ Use `print(n = ...)` to see more rows
[1] "Domain Code" "Domain" "Area Code" "Area"
[5] "Element Code" "Element" "Item Code" "Item"
[9] "Year Code" "Year" "Unit" "Value"
[13] "Flag" "Flag Description"
Conduct some exploratory data analysis, using dplyr commands such as group_by()
, select()
, filter()
, and summarise()
. Find the central tendency (mean, median, mode) and dispersion (standard deviation, mix/max/quantile) for different subgroups within the data set.
Year
Year Code 1961 1962 1963 1964 1965 1966
1961 1 0 0 0 0 0
1962 0 1 0 0 0 0
1963 0 0 1 0 0 0
1964 0 0 0 1 0 0
1965 0 0 0 0 1 0
1966 0 0 0 0 0 1
Be sure to explain why you choose a specific group. Comment on the interpretation of any interesting differences between groups that you uncover. This section can be integrated with the exploratory data analysis, just be sure it is included.
---
title: "Challenge 2"
author: "Lai Wei"
desription: "Data wrangling: using group() and summarise()"
date: "08/22/2022"
format:
html:
toc: true
code-fold: true
code-copy: true
code-tools: true
categories:
- challenge_2
---
```{r}
#| label: setup
#| warning: false
#| message: false
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)
```
## Challenge Overview
Today's challenge is to
1) read in a data set, and describe the data using both words and any supporting information (e.g., tables, etc)
2) provide summary statistics for different interesting groups within the data, and interpret those statistics
## Read in the Data
Read in one (or more) of the following data sets, available in the `posts/_data` folder, using the correct R package and command.
- railroad\*.csv or StateCounty2012.xlsx ⭐
- FAOstat\*.csv ⭐⭐⭐
- hotel_bookings ⭐⭐⭐⭐
```{r}
library(readr)
FAOSTAT_livestock <- read_csv("_data/FAOSTAT_livestock.csv")
View(FAOSTAT_livestock)
```
Add any comments or documentation as needed. More challenging data may require additional code chunks and documentation.
## Describe the data
Using a combination of words and results of R commands, can you provide a high level description of the data? Describe as efficiently as possible where/how the data was (likely) gathered, indicate the cases and variables (both the interpretation and any details you deem useful to the reader to fully understand your chosen data).
```{r}
#| label: summary
#Choose Area columns in FAOSTAT_livestock
select(FAOSTAT_livestock, starts_with("Area"))
#Show the col names in FAOSTAT_livestock
colnames(FAOSTAT_livestock)
```
## Provide Grouped Summary Statistics
Conduct some exploratory data analysis, using dplyr commands such as `group_by()`, `select()`, `filter()`, and `summarise()`. Find the central tendency (mean, median, mode) and dispersion (standard deviation, mix/max/quantile) for different subgroups within the data set.
```{r}
#Set Year as the col containing year in FAOSTAT_livestock with first six
Year <- head(select(FAOSTAT_livestock,contains("Year")))
#Make a table of Year
table(Year)
```
### Explain and Interpret
Be sure to explain why you choose a specific group. Comment on the interpretation of any interesting differences between groups that you uncover. This section can be integrated with the exploratory data analysis, just be sure it is included.